package com.example.hjlquickstartdemo.api;


import com.example.hjlquickstartdemo.pojo.dto.IdVersion;
import com.example.hjlquickstartdemo.pojo.dto.UserDto;
import com.example.hjlquickstartdemo.pojo.query.UserQuery;
import com.example.hjlquickstartdemo.pojo.vo.CommonPage;
import com.example.hjlquickstartdemo.pojo.vo.ResultResponse;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * User接口功能声明
 *
 * @author HeJiaLe
 * @date 2023/07/17 13:51
 **/

@CrossOrigin
@Api(tags = "用户管理 ")
@RequestMapping("/quickStartDemo/v1")
@Validated
public interface UserApi {
    /**
     *  增加用户 通过-> UserDto
     * @param userDto 用户信息
     * @return true成功 false失败
     */
    @ApiOperation( value = "增加用户",notes="界面增加用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "userDto", value = "用户数据", dataType = "UserDto", required = true)
    }
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/userAdd")
    ResultResponse<Boolean> add(@NotNull @Valid @RequestBody UserDto userDto);
    /**
     *  删除用户  通过->id
     * @param id  记录id
     * @return  true 成功 false失败
     */
    @ApiOperation(value = "删除用户通过id")
    @ApiImplicitParam(name = "id",required =true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/userRemove")
    ResultResponse<Boolean> remove(@PathVariable @NotNull Long id);

    /**
     *  比较删除用户 通过-> id和version
     * @param id  记录id
     * @param version 版本
     * @return  true 成功 false失败
     */
    @ApiOperation(value = "删除单个用户通过id和版本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",required =true,dataType = "Long",paramType = "query"),
            @ApiImplicitParam(name = "version",required =true,dataType = "Long",paramType = "query")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/userRemByVersion")
    ResultResponse<Boolean> remove(@NotNull @RequestParam("id") Long id,@NotNull @RequestParam("version") Long version);

    /**
     * 批量删除用户 通过-> idVersions[]
     *
     * @param idVersions
     * @return
     */
    @ApiOperation(value = "批量删除用户通过id和版本")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions",required =true,dataType = "IdVersion",paramType = "body")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/userBatchRem")
    ResultResponse<Boolean> remove(@NotEmpty @RequestBody  IdVersion[] idVersions);


    /**
     * 更新用户信息  通过-> userDto
     * @param userDto 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation( value = "更新用户信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "userDto",required =true,dataType = "UserDto",paramType = "body")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @PutMapping("/userUpdate")
    ResultResponse<Boolean> update(@NotNull @Valid @RequestBody UserDto userDto);

    /**
     * 界面调用接口更新用户信息
     * @param basicUserQuery 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "查询用户列表",notes = "支持模糊查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "basicUserQuery",required =true,dataType = "BasicUserQuery",paramType = "body")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    })
    @GetMapping("/userSearch")
    ResultResponse<CommonPage<UserDto>> search(@NotNull @Valid UserQuery basicUserQuery);

    /**
     *  页面编辑行的时候传id从后端加载数据
     * @param id  当前行id
     * @return  用户数据
     */
    @ApiOperation(value = "根据id获取用户",notes = "用于编辑和查看的时候获取用户")
    @ApiImplicitParam(name = "id",value = "主键值",required = true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功,非0码则代表失败"),
    })
    @GetMapping("/user/{id}")
    ResultResponse<UserDto> findById( @PathVariable @NotNull Long id);

}